package com.me.modules.report.controller;

import com.me.modules.common.controller.BaseController;
import com.me.modules.common.utils.JsonUtil;
import com.me.modules.report.service.SrmReportService;
import com.me.modules.sys.entity.CodeEntity;
import com.me.modules.sys.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 事件报表
 *
 * @author lill
 * @email lill5270@163.com
 * @date 2019-01-16 17:20:30
 */
@Controller
@RequestMapping("/report/srmreport")
public class SrmReportController extends BaseController{
	@Autowired
	private SrmReportService srmReportService;
	@Autowired
	private CodeService codeService;


	/**
	 * 列表
	 */
	@RequestMapping("/SrmClosePie")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String SrmClosePie(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List<Object> list =srmReportService.SrmClosePie(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/srm/SrmClosePie";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/SrmOrignPie")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String SrmOrignPie(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List<Object> list =srmReportService.SrmOrignPie(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/srm/SrmOrignPie";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/SrmTypePie")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String SrmTypePie(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List<Object> list =srmReportService.SrmTypePie(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/srm/SrmTypePie";
	}
	/**
	 * 列表
	 */
	@RequestMapping("/SrmLineOrginMonth")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String SrmLineOrginMonth(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List list =new ArrayList();
		List<CodeEntity> codeList  =codeService.queryChildsByMark("srmOrigin");
		list.add(codeList);
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new Date());
		}
		List listColumn = new ArrayList();
		for (CodeEntity code :codeList) {
			params.put("srmOrigin",code.getValue());
			List<Object> month =srmReportService.SrmLineOrginMonth(params);
			listColumn.add(month);
		}
		list.add(listColumn);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/srm/SrmLineOrginMonth";
	}


	/**
	 * 列表
	 */
	@RequestMapping("/SrmLineMonthNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String SrmLineMonthNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new  Date());
		}
		List<Object> list =srmReportService.SrmLineMonthNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/srm/SrmLineMonthNumber";
	}






}
